package com.xbongbong.pro.statistic.factory;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.pro.statistic.enums.StatisticsTypeEnum;
import com.xbongbong.pro.statistic.help.strategy.chart.ChartStrategyService;
import com.xbongbong.pro.statistic.help.strategy.chart.impl.AllChartStrategyServiceImpl;
import com.xbongbong.pro.statistic.help.strategy.chart.impl.CustomChartStrategyServiceImpl;
import com.xbongbong.pro.statistic.help.strategy.chart.impl.SystemChartStrategyServiceImpl;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 图表解析工厂
 * @author xinpeng.jiang
 * @version V1.0
 * @date 2021/5/17 10:09
 * @since V1.0
 */
@Component
public class ChartAnalysisFactory {

    private static final Map<Integer, ChartStrategyService> CHART_STRATEGY_SERVICE_MAP = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);

    @Resource
    private AllChartStrategyServiceImpl allChartStrategyServiceImpl;
    @Resource
    private CustomChartStrategyServiceImpl customChartStrategyServiceImpl;
    @Resource
    private SystemChartStrategyServiceImpl systemChartStrategyServiceImpl;

    @PostConstruct
    public void init() {
        CHART_STRATEGY_SERVICE_MAP.put(StatisticsTypeEnum.SYSTEM_STATISTIC.getCode(), systemChartStrategyServiceImpl);
        CHART_STRATEGY_SERVICE_MAP.put(StatisticsTypeEnum.CUSTOM_STATISTIC.getCode(), customChartStrategyServiceImpl);
        CHART_STRATEGY_SERVICE_MAP.put(StatisticsTypeEnum.ALL.getCode(), allChartStrategyServiceImpl);
    }

    public static ChartStrategyService getChartStrategyService(Integer statisticsType) {
        if (statisticsType == null) {
            return CHART_STRATEGY_SERVICE_MAP.get(StatisticsTypeEnum.SYSTEM_STATISTIC.getCode());
        }
        return CHART_STRATEGY_SERVICE_MAP.get(statisticsType);
    }
}
